package com.handinfo.android.ui.window;

import java.io.DataInputStream;
import java.io.IOException;

import android.graphics.Bitmap;
import android.graphics.Color;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.core.object.Actor;
import com.handinfo.android.core.object.Animation;
import com.handinfo.android.game.GameMessage;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.SimpleRole;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWAnimationBox;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWLabel;
import com.handinfo.android.uicontrols.controls.DWListSubItem;
import com.handinfo.android.uicontrols.controls.DWListbox;
import com.handinfo.android.uicontrols.controls.DWMessageBox;
import com.handinfo.android.uicontrols.controls.DWPaging;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

public class UIGetMoney implements IUIWindows
{

	public DWFrame m_gm_frame = null;
	private DWTitle m_gm_title = null;
	private DWImageBox m_imageBox_title = null;
	private Bitmap m_bm_title = null;
	private final int NUM = 16;
	private Bitmap[] m_gm_bt = new Bitmap[NUM];
	private DWBackground m_gm_bg = null;//主背景
	private DWBackground m_background_left = null;
	private DWBackground m_background_right = null;
	private DWBackground m_background_zhong = null;
	private DWListbox m_gm_listBox = null; //好友协助改成list
	private DWListSubItem[] m_gm_subItem;
	private DWLabel[] m_gm_Label;
	public DWImageBox[] m_gm_ib = new DWImageBox[NUM];
	private DWTextbox[] m_gm_tb = new DWTextbox[2];
	private DWLabel[] m_gm_label = new DWLabel[4];
	private DWButton m_gm_bn01 = null;
	public DWButton m_gm_bn02 = null;
	private Bitmap m_anxia01 = null;
	private Bitmap m_anxia02 = null;
	private DWListbox m_gm_lb = null;
	private DWListSubItem[] m_gm_lsi = new DWListSubItem[NUM];
	private String[] m_gm_chuan = new String[10];
	private DWTextbox m_jinggao_text = null;
	
	private DWTextbox m_shouhuo_tishi = null;
	private DWTextbox[][] m_haoyou_jiaoshui = new DWTextbox[num][3];
	private DWListSubItem[] m_haoyou_item = new DWListSubItem[num];
	private DWImageBox[] m_haoyou_tubian = new DWImageBox[num];
	private DWAnimationBox[] m_ab_other  = new DWAnimationBox[num];
	
	private DWAnimationBox m_ab_shu = null;
	private Actor m_actor_shu = null;
	private boolean isShowShu = false;

	private String str02 = null;
	private DWPaging m_gm_pg = null;
	//字符串
	private byte m_chuan_tishi = 0;
	private byte m_chuan_haoyou = 1;
	private byte m_chuan_jinggao = 2;
	private byte m_chuan_haoyoutishi = 3;
	private byte m_chuan_friend01 = 4;
	private byte m_chuan_friend02 = 5;
	private byte m_chuan_friend03 = 6;
	private byte m_chuan_friend04 = 7;
	private byte m_chuan_yuanbao = 8;
	private byte m_chuan_shuliang = 9;

	//label
	private byte m_label_tishi = 0;
	private byte m_label_haoyou = 1;
	private byte m_label_jinggao = 2;
	private byte m_label_haiyoubiaoti = 3;//好友区标题
	private DWLabel m_label_lv = null;
	private DWLabel m_label_jiaosui = null;
	//text
//	private byte m_text_friend01 = 0;
//	private byte m_text_friend02 = 1;
//	private byte m_text_friend03 = 2;
//	private byte m_text_friend04 = 3;
	private byte m_text_yuanbao = 0;
	private byte m_text_shuliang = 1;

	public byte m_gm_close = 0;//关闭窗口
	private byte m_gm_beijing01 = 1;//拼接背景01
	private byte m_gm_beijing02 = 2;//拼接背景02
//	private byte m_gm_beijing03 = 3;//后置背景1
//	private byte m_gm_beijing04 = 4;//后置背景2
	private byte m_gm_yaoqianshu = 5;//摇钱树
	private byte m_gm_mingshuidi = 6;//亮水滴
	private byte m_gm_anshuidi = 7;//暗水滴
//	private byte m_gm_yihao = 8;//第一个水滴
//	private byte m_gm_erhao = 9;//第二个水滴
//	private byte m_gm_sanhao = 10;//第三个水滴
//	private byte m_gm_sihao = 11;//第四个水滴
//	private byte m_gm_wuhao = 12;//第五个水滴
	private byte m_gm_shiyong = 8;//按钮图标
	private byte m_gm_jiaoshui = 9;

	//分页
	private DWImageBox m_ib_left = null;
	private DWImageBox m_ib_right = null;
	private Bitmap m_bm_left = null;
	private Bitmap m_bm_right = null;
	private DWTextbox m_text_str = null;
	private String m_str = null;

	//消息确认框
	private DWMessageBox m_gm_messageBox = null;
	private String m_messageBox_str = null;

	private String[] m_yqs_bmFriend; //帮忙好友
	private SimpleRole[] m_yqs_xyjsFriend; //需要浇水的好友

	long m_yqs_id; //摇钱树id
	byte m_yqs_status; //摇钱树状态 -1功能未开启 1生产中 2收获 3已经收获
	byte m_yqs_level; //摇钱树等级
	Short m_yqs_getMoney; //可以生产的元宝数
	byte m_yqs_maxSD; //总水滴数
	byte m_yqs_haveSD; //已经浇灌滴数
	boolean m_yqs_isWarteing;//自己是否可以浇灌

	private DWImageBox[] m_gm_imageBox;//画水滴
	private DWAnimationBox[] m_ab_owm;//自己水滴的动画
	private Actor m_actor_shuidi = null;//水滴动画对象
	
	private boolean m_isShowWater = false;//是否显示动画（自己水滴）

	private boolean flag = false;
	private int index = 0;//下标 

	private void yaoqian()
	{

		//窗口
		m_gm_frame = new DWFrame(DWFrame.FRAME_TYPE_FULL, true);
		m_gm_frame.setClickClose(false);
		m_gm_title = new DWTitle("", m_gm_frame);
		m_imageBox_title = new DWImageBox(m_bm_title);
		m_imageBox_title.setNearAnchor(m_gm_title, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		//关闭X
		m_gm_ib[m_gm_close] = new DWImageBox(m_gm_bt[m_gm_close]);
		m_gm_ib[m_gm_close].setNearAnchor(m_gm_title, Tools.RIGHT_TOP, Tools.RIGHT_TOP, 0, 0);
		//背景
		m_gm_bg = new DWBackground(750, 380);
		m_gm_bg.setShow(false);
		m_gm_bg.setNearAnchor(m_gm_frame, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		//
		m_background_left = new DWBackground(400, 370);
		if(DWGameManager.AdpaterType == 2){
			m_background_left.setShowWideHigh(DWGameManager.Screen_Width/2, DWGameManager.Screen_Height*37/48);
		}
		m_background_left.setFill(false);
		m_background_left.setNearAnchor(m_gm_frame, Tools.LEFT_TOP, Tools.LEFT_TOP, 20, 40);
		
		m_background_right = new DWBackground(320, 340);
		if(DWGameManager.AdpaterType == 2){
			m_background_right.setShowWideHigh(DWGameManager.Screen_Width*32/80, DWGameManager.Screen_Height*34/48);
		}
		m_background_right.setFill(false);
		if(DWGameManager.AdpaterType == 2){
			m_background_right.setNearAnchor(m_background_left, Tools.LEFT_TOP, Tools.RIGHT_TOP, 10, 0);
		}else{
			m_background_right.setNearAnchor(m_gm_frame, Tools.LEFT_TOP, Tools.LEFT_TOP, 425, 40);
		}
		
		m_background_zhong = new DWBackground(180, 225);
		if(DWGameManager.AdpaterType == 2){
			m_background_zhong.setShowWideHigh(DWGameManager.Screen_Width*18/80, DWGameManager.Screen_Height*225/480);
		}
		m_background_zhong.setFill(true);
		m_background_zhong.setNearAnchor(m_gm_frame, Tools.LEFT_TOP, Tools.LEFT_TOP, 40, 80);
		
		refreshTree();
		
	
		m_gm_frame.addControl(m_gm_bg);
		m_gm_frame.addControl(m_background_left);
		m_gm_frame.addControl(m_background_right);
		m_gm_frame.addControl(m_background_zhong);
		m_gm_frame.addControl(m_gm_title);
		m_gm_frame.addControl(m_gm_listBox);//好友协助
		m_gm_frame.addControl(m_gm_bn01);
		m_gm_frame.addControl(m_gm_bn02);
		m_gm_frame.addControl(m_shouhuo_tishi);
		for (int i = 0; i < 2; i++) {
			m_gm_frame.addControl(m_gm_tb[i]);
		}
	
		
		for (int i = 0; i < NUM; i++) {
			m_gm_frame.addControl(m_gm_ib[i]);
		}
		for (int i = 0; i < m_yqs_maxSD; i++) {
			m_gm_frame.addControl(m_gm_imageBox[i]);
			m_gm_frame.addControl(m_ab_owm[i]);
		}
		m_gm_frame.addControl(m_gm_label[m_label_haoyou]);
		m_gm_frame.addControl(m_gm_label[m_label_tishi]);
		m_gm_frame.addControl(m_jinggao_text);
		m_gm_frame.addControl(m_imageBox_title);
		DWControlsManager.getInstance().addControl(m_gm_frame);

		//关闭窗口
		m_gm_ib[m_gm_close].addListener(new DWListener() {
			public void OnDoubleClick()
			{
			}

			public void OnClick()
			{
				UIWindows.getInstance().m_getMoney.close((byte) 0);

			}
		});

	}

	//好友列表监听
	private DWListener m_listBox_jiaoshui = new DWListener() {
		
		public void OnDoubleClick() {
		}
		
		public void OnClick() {
			index = m_gm_lb.getTouchIndex();
			//判断是否需要浇水
			if (m_yqs_xyjsFriend[index].m_isWatering == 1) {
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
						"已经不能浇水了");
			}
			else {
				DWGameManager.getInstance().getSendMessage().sendwatering(m_yqs_xyjsFriend[index].m_gameID);
			}
			
		}
	};
	
	
	//使用元宝
	private DWListener m_shiyong = new DWListener() {
		
		public void OnDoubleClick() {
		}
		
		public void OnClick() {
			UIWindows.getInstance().m_getMoney.close((byte)0);
			DWGameManager.getInstance().getSendMessage().sendOpenVipShop((byte) 1, (byte) 0);
		}
	};
	
	//浇水监听
	private DWListener m_jiaoguan = new DWListener() {

		public void OnDoubleClick()
		{
		}

		public void OnClick()
		{
			if (m_yqs_status == 1) {
				if (m_yqs_isWarteing == true) {
//					m_gm_bn02.setName("浇灌");
					//发送浇灌
					DWGameManager.getInstance().getSendMessage().sendwatering(
							DWGameManager.getInstance().m_role.m_gameId);
				}

			}
			else if (m_yqs_status == 2) {//可以收获
				
				DWGameManager.getInstance().getSendMessage().sendYQSReap(m_yqs_getMoney);

			}
			else if (m_yqs_status == 3) {
//				m_shouhuo_tishi.setText("收获完成");
			}

		}
	};
	//左翻页
	private DWListener m_left = new DWListener() {

		public void OnDoubleClick()
		{
		}

		public void OnClick()
		{
			if (m_friend_currentPage == 0) {
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
						"当前是最小页");
			}
			else {
				DWGameManager.getInstance().getSendMessage().sendYQSFriendList((byte) 0,
						m_friend_currentPage - 1, num);
			}

		}
	};
	//右翻页
	private DWListener m_right = new DWListener() {

		public void OnDoubleClick()
		{
		}

		public void OnClick()
		{

			if (m_friend_currentPage + 1 == m_friend_totalPage) {
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
						"当前是最大页");
			}
			else {
				DWGameManager.getInstance().getSendMessage().sendYQSFriendList((byte) 0,
						m_friend_currentPage + 1, num);
			}
		}
	};

	public void init()
	{
		m_gm_bt[m_gm_close] = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");
		m_bm_title = UIWindows.createImage("/img/newui/yaoqianshu_1.gnp");
		m_gm_bt[m_gm_yaoqianshu] = UIWindows.createImage("/img/newui/yaoqianshuyqs_1.gnp");
		m_gm_bt[m_gm_mingshuidi] = UIWindows.createImage("/img/newui/yaoqianshugg_1.gnp");
		m_gm_bt[m_gm_anshuidi] = UIWindows.createImage("/img/newui/yaoqianshugg_2.gnp");
		m_gm_bt[m_gm_shiyong] = UIWindows.createImage("/img/newui/anniu_10.gnp");
		m_gm_bt[m_gm_jiaoshui] = UIWindows.createImage("/img/newui/anniu_10ax.gnp");
		m_anxia01 = UIWindows.createImage("/img/newui/anniu_1ax.gnp");
		m_anxia02 = UIWindows.createImage("/img/newui/anniu_1ax.gnp");
		m_bm_left = UIWindows.createImage("/img/newui/haoyoufyan_2.gnp");
		m_bm_right = UIWindows.createImage("/img/newui/haoyoufyan_1.gnp");
		//水滴动画
		Animation chicheng = UIWindows.createAnimation("/anim/shuidipo_1.anim");
		m_actor_shuidi = new Actor(chicheng);
		Animation chicheng1 = UIWindows.createAnimation("/anim/yaoqianshu_1.anim");
		m_actor_shu = new Actor(chicheng1);
	}

	private void refreshTree(){
		
		m_gm_chuan[m_chuan_tishi] = m_yqs_level + "级摇钱树，需要浇灌"+m_yqs_maxSD+"次,能收获" + m_yqs_getMoney + "元宝";
		m_gm_chuan[m_chuan_haoyou] = "今日协助浇水好友";
		m_gm_chuan[m_chuan_jinggao] = "<mark c=FF0000>明天才能再次浇灌 </mark>";
		m_gm_chuan[m_chuan_friend01] = "小一";
		m_gm_chuan[m_chuan_friend02] = "小二";
		m_gm_chuan[m_chuan_friend03] = "小三";
		m_gm_chuan[m_chuan_friend04] = "小四";
		m_gm_chuan[m_chuan_yuanbao] = "当前元宝";
		m_gm_chuan[m_chuan_shuliang] = "20";
		//
		m_gm_label[m_label_tishi] = new DWLabel(m_gm_chuan[m_chuan_tishi]);
		m_gm_label[m_label_tishi].setTextColor(Color.GREEN);
		m_gm_label[m_label_tishi].setBackgroundColor(Tools.ALPHA);
		m_gm_label[m_label_tishi].setNearAnchor(m_background_left, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 10);

		m_gm_label[m_label_haoyou] = new DWLabel(m_gm_chuan[m_chuan_haoyou]);
		m_gm_label[m_label_haoyou].setTextColor(Color.YELLOW);
		m_gm_label[m_label_haoyou].setBackgroundColor(Tools.ALPHA);
		if(DWGameManager.AdpaterType == 2){
			m_gm_label[m_label_haoyou].setNearAnchor(m_gm_title, Tools.LEFT_TOP, Tools.LEFT_TOP, 400, 100);
		}else{
			m_gm_label[m_label_haoyou].setNearAnchor(m_gm_title, Tools.LEFT_TOP, Tools.LEFT_TOP, 230, 100);		
		}

		//摇钱树
		m_gm_ib[m_gm_yaoqianshu] = new DWImageBox(m_gm_bt[m_gm_yaoqianshu]);
		m_gm_ib[m_gm_yaoqianshu].setNearAnchor(m_background_left, Tools.LEFT_TOP, Tools.LEFT_TOP, 20, 50);
		//动画
		m_ab_shu = new DWAnimationBox(m_actor_shu);
		m_ab_shu.setNearAnchor(m_gm_ib[m_gm_yaoqianshu], Tools.HCENTER_BOTTOM, Tools.HCENTER_VCENTER, 0, 0);
		//使用银票
		m_gm_bn01 = new DWButton("使用元宝", m_gm_bt[m_gm_shiyong]);
		m_gm_bn01.setDownImage(m_gm_bt[m_gm_jiaoshui]);
		m_gm_bn01.setDownImage(m_anxia01);
		m_gm_bn01.addListener(m_shiyong);
		if(DWGameManager.AdpaterType == 2){
			m_gm_bn01.setNearAnchor(m_gm_ib[m_gm_yaoqianshu], Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, 60, 155);
		}else{
			m_gm_bn01.setNearAnchor(m_gm_ib[m_gm_yaoqianshu], Tools.RIGHT_BOTTOM, Tools.RIGHT_BOTTOM, 60, 105);	
		}

		//浇灌
		m_gm_bn02 = new DWButton("浇灌", m_gm_bt[m_gm_shiyong]);
		m_gm_bn02.setDownImage(m_gm_bt[m_gm_jiaoshui]);
		m_gm_bn02.addListener(m_jiaoguan);
		m_gm_bn02.setNearAnchor(m_gm_bn01, Tools.LEFT_TOP ,Tools.RIGHT_TOP, 10, 0);

		//警告
//		m_gm_label[m_label_jinggao] = new DWLabel(" ");
//		m_gm_label[m_label_jinggao].setName(m_gm_chuan[m_chuan_jinggao]);
//		m_gm_label[m_label_jinggao].setTextColor(Color.RED);
//		m_gm_label[m_label_jinggao].setBackgroundColor(Tools.ALPHA);
		m_jinggao_text = new DWTextbox("");
		m_jinggao_text.setNearAnchor(m_background_zhong, Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM, 0, 20);

		//摇钱树状态提示
		m_shouhuo_tishi = new DWTextbox("");
		m_shouhuo_tishi.setNearAnchor(m_gm_ib[m_gm_yaoqianshu], Tools.LEFT_TOP, Tools.LEFT_TOP, 50, 50);
		if (m_yqs_status == 1) {
			isShowShu = false;
			if (m_yqs_isWarteing == true) {
				m_gm_bn02.setName("浇灌");
				
			}
			else {
				m_gm_bn02.setName("已浇灌");
			}

		}
		else if (m_yqs_status == 2) {//可以收获
			m_gm_bn02.setName("可以收获");
			m_jinggao_text.setText(m_gm_chuan[m_chuan_jinggao]);
			isShowShu = true;
		}
		else if (m_yqs_status == 3) {
			m_gm_bn02.setName("已收获");
			m_jinggao_text.setText(m_gm_chuan[m_chuan_jinggao]);
			isShowShu = false;
		}

		//协助浇水好友
		m_gm_listBox = new DWListbox(140, 180);
		m_gm_listBox.removeAllSubItem();
		m_gm_listBox.setNearAnchor(m_gm_label[m_label_haoyou], Tools.LEFT_TOP,Tools.LEFT_BOTTOM, 10,10);
		m_gm_subItem = new DWListSubItem[m_yqs_bmFriend.length];
		m_gm_Label = new DWLabel[m_yqs_bmFriend.length];
		for(int i = 0;i < m_yqs_bmFriend.length;i++){
			m_gm_subItem[i] = new DWListSubItem();
			m_gm_Label[i] = new DWLabel("");
			m_gm_Label[i].setFont(DWFont.getFont(20));
			m_gm_Label[i].setName(m_yqs_bmFriend[i]);
			m_gm_Label[i].resetWideHigh();
			m_gm_Label[i].setShowBackground(false);
			m_gm_Label[i].setTextColor(Color.WHITE);
			m_gm_Label[i].setNearAnchor(m_gm_subItem[i], Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
			
			m_gm_subItem[i].addControls(m_gm_Label[i]);
			m_gm_listBox.addSubItem(m_gm_subItem[i]);
			
		}
		

		//当前元宝
		m_gm_tb[m_text_yuanbao] = new DWTextbox(m_gm_chuan[m_chuan_yuanbao]+":");
		if(DWGameManager.AdpaterType == 2){
			m_gm_tb[m_text_yuanbao].setNearAnchor(m_gm_ib[m_gm_yaoqianshu], Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM, 0, 150);
		}else{
			m_gm_tb[m_text_yuanbao].setNearAnchor(m_gm_ib[m_gm_yaoqianshu], Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM, 0, 100);	
		}
		//元宝数量
		
		m_gm_tb[m_text_shuliang] = new DWTextbox(""+DWGameManager.getInstance().m_role.m_rmb);
		m_gm_tb[m_text_shuliang].setNearAnchor(m_gm_tb[m_text_yuanbao], Tools.LEFT_TOP, Tools.RIGHT_TOP, 0, 0);
		
		//画水滴
		m_gm_imageBox = new DWImageBox[m_yqs_maxSD];// 
		//对应的动画
		m_ab_owm = new DWAnimationBox[m_yqs_maxSD];
		if( m_yqs_maxSD <= 7 ){
			for (int i = 0; i < m_yqs_maxSD; i++) {
				m_gm_imageBox[i] = new DWImageBox(m_gm_bt[m_gm_anshuidi]);
				m_gm_imageBox[i].setNearAnchor(m_gm_ib[m_gm_yaoqianshu],
						Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 30 + 20 * i, 10);
				//水滴对应的动画
				waterAB(i);
			}
		}else{
			for (int i = 0; i < 7; i++) {//第一排先画7个
				m_gm_imageBox[i] = new DWImageBox(m_gm_bt[m_gm_anshuidi]);
				m_gm_imageBox[i].setNearAnchor(m_gm_ib[m_gm_yaoqianshu],
						Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 30 + 20 * i, 10);
				//水滴对应的动画
				waterAB(i);
			}
			for(int j = 7; j<m_yqs_maxSD;j++){
				m_gm_imageBox[j] = new DWImageBox(m_gm_bt[m_gm_anshuidi]);
				m_gm_imageBox[j].setNearAnchor(m_gm_imageBox[0],
						Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 20 * (j-7), 5);
				//水滴对应的动画
				waterAB(j);
			}
		}

		for (int i = 0; i < m_yqs_haveSD; i++) {
			m_gm_frame.removeControl(m_gm_imageBox[i]);
			m_gm_frame.addControl(m_gm_imageBox[i]);
			m_gm_imageBox[i].setImage(m_gm_bt[m_gm_mingshuidi]);
		}
	
		m_gm_frame.addControl(m_gm_label[m_label_tishi]);
		m_gm_frame.addControl(m_gm_label[m_label_haoyou]);
		m_gm_frame.addControl(m_gm_ib[m_gm_yaoqianshu]);
		m_gm_frame.addControl(m_gm_bn01);
		m_gm_frame.addControl(m_gm_bn02);
		m_gm_frame.addControl(m_jinggao_text);
		m_gm_frame.addControl(m_shouhuo_tishi);
		m_gm_frame.addControl(m_gm_tb[m_text_yuanbao]);
		m_gm_frame.addControl(m_gm_tb[m_text_shuliang]);
		
		
	}
	
	/**
	 * 水滴动画
	 */
	private void waterAB(int i){
		m_ab_owm[i] = new DWAnimationBox(m_actor_shuidi);
		m_ab_owm[i].setShow(false);
		m_ab_owm[i].setNearAnchor(m_gm_imageBox[i], Tools.HCENTER_BOTTOM, Tools.HCENTER_VCENTER, 0, 0);
	}
	/**
	 * 控制哪个显示
	 */
	private void isShowAb(int i){
		m_ab_owm[i].setShow(true);
	}
	/**
	 * 全部不显示
	 */
	private void unShow(){
		for(int i = 0;i < m_yqs_maxSD;i++){
			m_ab_owm[i].setShow(false);
		}
		if(m_isShowWater){
			m_haoyou_item[index].removeControl(m_ab_other[index]);
			m_isShowWater = false;
		}
	}
	/*
	 * 刷新lostbox
	 */
	
	private void refreshLost(){
		if(DWGameManager.AdpaterType == 2){
			m_gm_chuan[m_chuan_haoyoutishi] = "  好友         " + "    " + " 等级  " + "  " + " 浇灌";
		}else{
			m_gm_chuan[m_chuan_haoyoutishi] = "  好友         " + "         " + " 等级  " + "  " + "" + "  " + " 浇灌";
		}
		//好友提示区
			m_gm_label[m_label_haiyoubiaoti] = new DWLabel("好友");
			m_gm_label[m_label_haiyoubiaoti].setShowWideHigh(DWGameManager.Screen_Width*18/80, m_gm_tb[m_text_shuliang].getShowHeight());
			m_gm_label[m_label_haiyoubiaoti].setTextColor(Color.WHITE);
			m_gm_label[m_label_haiyoubiaoti].setShowBackground(false);
			m_gm_label[m_label_haiyoubiaoti].setNearAnchor(m_background_right, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 20);
			
			m_label_lv = new DWLabel("等级");
			m_label_lv.setShowWideHigh(DWGameManager.Screen_Width*6/80, m_gm_tb[m_text_shuliang].getShowHeight());
			m_label_lv.setTextColor(Color.WHITE);
			m_label_lv.setShowBackground(false);
			m_label_lv.setNearAnchor(m_gm_label[m_label_haiyoubiaoti], Tools.LEFT_TOP, Tools.RIGHT_TOP, 0, 0);
			
			m_label_jiaosui = new DWLabel("浇灌");
			m_label_jiaosui.setTextColor(Color.WHITE);
			m_label_jiaosui.setShowBackground(false);
			m_label_jiaosui.setNearAnchor(m_label_lv, Tools.LEFT_TOP, Tools.RIGHT_TOP, 0, 0);
			//好友区
			m_gm_frame.removeControl(m_gm_lb);
			m_gm_lb = null;
			if(DWGameManager.AdpaterType == 2){
				m_gm_lb = new DWListbox(DWGameManager.Screen_Width*29/80, DWGameManager.Screen_Height*27/48);
			}else{
				m_gm_lb = new DWListbox(290, 270);
			}
			m_gm_lb.addListener(m_listBox_jiaoshui);
			m_gm_lb.setShowBackgroundRect(true);
			m_gm_lb.setLineSpacing(15);
			m_gm_lb.setNearAnchor(m_background_right, Tools.LEFT_TOP, Tools.LEFT_TOP, 10, 50);	
						
		m_gm_lb.removeAllSubItem();
		for(int n = 0; n < num;n++){
			m_haoyou_jiaoshui[n][0] = null;
			m_haoyou_jiaoshui[n][1] = null;
			m_haoyou_tubian[n] = null;
			if(m_ab_other != null && m_ab_other[n] != null){
				m_ab_other[n] = null;
			}
		}
		if (m_yqs_xyjsFriend == null) {
//			DWGameManager.getInstance().showToast("您还没有添加好友！", Toast.LENGTH_SHORT);
//			return;
		}
		else {
			m_gm_frame.removeControl(m_text_str);
			m_ib_left = null;
			m_ib_right = null;
			m_text_str = null;
			m_str = null;
//			m_str = "";
			for (int i = 0; i < m_yqs_xyjsFriend.length; i++) {
				m_haoyou_item[i] = new DWListSubItem();
				if (m_yqs_xyjsFriend[i].m_isWatering == 1) {//不能

					if (m_yqs_xyjsFriend[i].m_online == true) {
						if(DWGameManager.AdpaterType == 2){
							m_haoyou_jiaoshui[i][0] = new DWTextbox(m_yqs_xyjsFriend[i].m_name,DWGameManager.Screen_Width*18/80);
							m_haoyou_jiaoshui[i][1] = new DWTextbox("" + m_yqs_xyjsFriend[i].m_grade,DWGameManager.Screen_Width*6/80);
						}else{
							m_haoyou_jiaoshui[i][0] = new DWTextbox(m_yqs_xyjsFriend[i].m_name,180);
							m_haoyou_jiaoshui[i][1] = new DWTextbox("" + m_yqs_xyjsFriend[i].m_grade,60);
						}
						
					}
					else {
						if(DWGameManager.AdpaterType == 2){
							m_haoyou_jiaoshui[i][0] = new DWTextbox("<mark c=818080>"+m_yqs_xyjsFriend[i].m_name+"</mark>",DWGameManager.Screen_Width*18/80);
							m_haoyou_jiaoshui[i][1] = new DWTextbox("<mark c=818080>---</mark>",DWGameManager.Screen_Width*6/80);
						}else{
							m_haoyou_jiaoshui[i][0] = new DWTextbox("<mark c=818080>"+m_yqs_xyjsFriend[i].m_name+"</mark>",180);
							m_haoyou_jiaoshui[i][1] = new DWTextbox("<mark c=818080>---</mark>",60);
						}
						
					}

					m_haoyou_tubian[i] = new DWImageBox(m_gm_bt[m_gm_anshuidi]);
					m_haoyou_tubian[i].setShow(false);
					m_ab_other[i] = new DWAnimationBox(m_actor_shuidi);
				}
				else {//可以浇水
					if (m_yqs_xyjsFriend[i].m_online == true) {
						if(DWGameManager.AdpaterType == 2){
							m_haoyou_jiaoshui[i][0] = new DWTextbox(m_yqs_xyjsFriend[i].m_name,DWGameManager.Screen_Width*18/80);
							m_haoyou_jiaoshui[i][1] = new DWTextbox("" + m_yqs_xyjsFriend[i].m_grade,DWGameManager.Screen_Width*6/80);
						}else{
							m_haoyou_jiaoshui[i][0] = new DWTextbox(m_yqs_xyjsFriend[i].m_name,180);
							m_haoyou_jiaoshui[i][1] = new DWTextbox("" + m_yqs_xyjsFriend[i].m_grade,60);
						}
					
					}
					else {
						if(DWGameManager.AdpaterType == 2){
							m_haoyou_jiaoshui[i][0] = new DWTextbox("<mark c=818080>"+m_yqs_xyjsFriend[i].m_name+"</mark>",DWGameManager.Screen_Width*18/80);
							m_haoyou_jiaoshui[i][1] = new DWTextbox("<mark c=818080>---</mark>",DWGameManager.Screen_Width*6/80);
						}else{
							m_haoyou_jiaoshui[i][0] = new DWTextbox("<mark c=818080>"+m_yqs_xyjsFriend[i].m_name+"</mark>",180);
							m_haoyou_jiaoshui[i][1] = new DWTextbox("<mark c=818080>---</mark>",60);
						}
					
					}
					m_haoyou_tubian[i] = new DWImageBox(m_gm_bt[m_gm_mingshuidi]);
					m_ab_other[i] = new DWAnimationBox(m_actor_shuidi);
				}
				m_haoyou_jiaoshui[i][0].setNearAnchor(m_haoyou_item[i], Tools.LEFT_TOP, Tools.LEFT_TOP, 0, 0);
				m_haoyou_jiaoshui[i][1].setNearAnchor(m_haoyou_jiaoshui[i][0], Tools.LEFT_TOP, Tools.RIGHT_TOP, 0, 0);
				m_haoyou_tubian[i].setNearAnchor(m_haoyou_jiaoshui[i][1], Tools.LEFT_TOP, Tools.RIGHT_TOP, 10, 0);
				m_ab_other[i].setNearAnchor(m_haoyou_tubian[i], Tools.HCENTER_BOTTOM, Tools.HCENTER_VCENTER, 0, 0);

				m_haoyou_item[i].addControls(m_haoyou_jiaoshui[i][0]);
				m_haoyou_item[i].addControls(m_haoyou_jiaoshui[i][1]);
				m_haoyou_item[i].addControls(m_haoyou_tubian[i]);
				m_gm_lb.addSubItem(m_haoyou_item[i]);
			}

		}//else
		//页码
		m_ib_left = new DWImageBox(m_bm_left);
		m_ib_left.addListener(m_left);
		m_ib_left.setNearAnchor(m_background_right, Tools.LEFT_BOTTOM, Tools.LEFT_BOTTOM, 80, 40);
		if(m_friend_totalPage==0){
			m_friend_totalPage=1;
		}
		m_str = "" + (m_friend_currentPage + 1) + "/" + m_friend_totalPage;
		if(DWGameManager.AdpaterType == 2){
			m_text_str = new DWTextbox(m_str,DWGameManager.Screen_Width/10);
		}else{
			m_text_str = new DWTextbox(m_str,80);
		}
		m_text_str.setNearAnchor(m_ib_left, Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 10, 0);
		m_ib_right = new DWImageBox(m_bm_right);
		m_ib_right.addListener(m_right);
		m_ib_right.setNearAnchor(m_ib_left, Tools.LEFT_TOP, Tools.LEFT_TOP, 100, 0);
		
		
		
		m_gm_frame.addControl(m_ib_left);
		m_gm_frame.addControl(m_text_str);
		m_gm_frame.addControl(m_ib_right);
		
		m_gm_frame.addControl(m_gm_label[m_label_haiyoubiaoti]);
		m_gm_frame.addControl(m_label_lv);
		m_gm_frame.addControl(m_label_jiaosui);
		m_gm_frame.addControl(m_gm_lb);
		

		
	}
	public void open(byte index)
	{
		if (flag == false) {
			yaoqian();
			flag = true;
		}
		else {
			if(m_gm_frame != null){
				DWControlsManager.getInstance().addControl(m_gm_frame);
			}else{
				return;
			}
			
		}

	}

	public void close(byte index)
	{
		flag = false;
		DWControlsManager.getInstance().removeControl(m_gm_frame);
	}

	public void dispose()
	{
	}

	/**
	 * 摇钱树开启界面
	 * @param dis
	 * @throws IOException
	 */
	public void recvYaoQianShu(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_摇钱树);
		byte state = dis.readByte(); //0:失败 1:成功
		if (state == 0) {
			DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
					"摇钱树未开启");
			return;
		}
		else if (state == 1) {
			m_yqs_id = dis.readLong(); //摇钱树id
			m_yqs_status = dis.readByte(); //摇钱树状态 -1功能未开启 1生产中 2收获 3已经收获
			m_yqs_level = dis.readByte(); //摇钱树等级
			m_yqs_getMoney = dis.readShort(); //可以生产的元宝数
			m_yqs_maxSD = dis.readByte(); //总水滴数
			m_yqs_haveSD = dis.readByte(); //已经浇灌滴数
			m_yqs_isWarteing = (dis.readByte() == 0 ? false : true);//0：不能	1：能
			byte bmSize = dis.readByte(); //帮忙好友数
			m_yqs_bmFriend = new String[bmSize];
			for (int i = 0; i < bmSize; i++) {
				m_yqs_bmFriend[i] = dis.readUTF();
			}
			m_yqs_xyjsFriend = null;
			m_friend_currentPage = 0;
			m_friend_totalPage = 1;
			UIWindows.getInstance().m_getMoney.open((byte) 0);
		}
	}

	/**
	 * 收获元宝
	 * @param dis
	 * @throws IOException
	 */
	public void recvReapYQS(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_摇钱树);
		byte state = dis.readByte(); //状态 0未知错误  1成功  2状态错误    4数量验证错误
		switch (state) {
			case 0:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_C,
						"未知错误");
				break;
			case 1:
				int yuanbaoNum = dis.readInt(); //获得元宝数量
				m_yqs_level = dis.readByte(); //当前等级
				m_yqs_getMoney = dis.readShort(); //当前级别可生产元宝	
				m_yqs_status = 3;
				Tools.debugPrintln("----------------in----------");
				//提示收获多少a
				m_gm_bn02.setName("已经收获");
				isShowShu = false;
				m_gm_messageBox = new DWMessageBox("元宝提示", "你获得元宝数量：` " + yuanbaoNum);
				final int num = yuanbaoNum;
				m_gm_frame.addControl(m_gm_messageBox);
				m_gm_messageBox.addListener(new DWListener() {

					public void OnDoubleClick()
					{
					}

					public void OnClick()
					{
						if (m_gm_messageBox.getResult() == DWMessageBox.SOFTKEY_OK) {
							m_gm_frame.removeControl(m_gm_messageBox);
						}
						else if (m_gm_messageBox.getResult() == DWMessageBox.SOFTKEY_BACK) {
							m_gm_frame.removeControl(m_gm_messageBox);
						}
						if(m_gm_tb[m_text_shuliang] != null){
							m_gm_tb[m_text_shuliang].setText(String.valueOf(DWGameManager.getInstance().m_role.m_rmb));						
						}
						
//						UIWindows.getInstance().m_getMoney.close((byte)0);
//						UIWindows.getInstance().m_getMoney.open((byte)0);
					}
				});
				break;
			case 2:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_C,
						"状态错误");
				break;
			case 4:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_C,
						"数量验证错误");
				break;
		}
	}

	/**
	 * 浇灌
	 * @param dis
	 * @throws IOException
	 */
	public void recvWarteing(DataInputStream dis) throws IOException
	{

		byte state = dis.readByte(); //状态 0:失败  1:成功  2:摇钱树状态错误   3:今天已浇过水
		long id;
		switch (state) {
			case 0:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_C,
						"浇灌失败");
				break;
			case 1:
				m_yqs_status = dis.readByte(); //摇钱树状态 、
				m_yqs_haveSD = dis.readByte(); //摇钱树已浇灌水滴数
				id = dis.readLong(); //被浇灌角色id 
				Tools.debugPrintln("--"+m_yqs_status+"--"+m_yqs_haveSD+"--"+id);
				if(DWGameManager.getInstance().m_role.m_gameId == id){
//					refreshTree();
					for(int i = 0; i< m_yqs_haveSD;i++){
						m_gm_imageBox[i].setBackground(m_gm_bt[m_gm_mingshuidi],false);
						isShowAb(m_yqs_haveSD - 1);
					}
					if(m_yqs_status == 1){
						m_gm_bn02.setName("已浇灌");
					}else if(m_yqs_status == 2){
						m_gm_bn02.setName("可以收获");
					}
					if(m_yqs_status == 2){
						isShowShu = true;
					}
				}else{//好友列表浇水
					m_haoyou_tubian[index].setBackground(m_gm_bt[m_gm_anshuidi], false);
					m_haoyou_tubian[index].setShow(false);
//					m_ab_other[index].setShow(true);
					m_haoyou_item[index].addControls(m_ab_other[index]);
					m_isShowWater = true;
										
				}
				//显示动画
				m_num = 0;
				break;
			case 2:
				m_yqs_status = dis.readByte(); //摇钱树状态
				m_yqs_haveSD = dis.readByte(); //摇钱树已浇灌水滴数
				id = dis.readLong(); //被浇灌角色id 
				refreshTree();
				break;
			case 3:
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B,
						"今天已经浇过水");
				break;
		}
	}

	/**
	 * 读取社交界面
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvYQSFriendList(DataInputStream dis) throws IOException
	{
		m_yqs_xyjsFriend = null;
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_社交);
		byte state = dis.readByte();
		Tools.debugPrintln("social list state = " + state);
		if (state == 1) {
			byte listType = dis.readByte();// 列表类型
			Tools.debugPrintln("type = " + listType);

			int currentPage = dis.readInt();//当前页
			if (currentPage == -1) {
				return;
			}
			Tools.debugPrintln("currentPage = " + currentPage);
			int sumPag = dis.readInt();

			int listCount = dis.readInt();
			Tools.debugPrintln("社交列表添加数量 : " + listCount);
			SimpleRole[] m_social_list = new SimpleRole[listCount];
			for (int i = 0; i < listCount; i++) {
				SimpleRole role = new SimpleRole();
				role.m_online = dis.readByte() == 0 ? true : false;// 是否在线
				// 0在线
				// 1不在线
				role.m_gameID = dis.readLong();
				role.m_name = dis.readUTF();
				Tools.debugPrintln("online = " + role.m_online);
				Tools.debugPrintln("id = " + role.m_gameID);
				Tools.debugPrintln("name = " + role.m_name);
				if (role.m_online) {
					role.m_grade = dis.readInt();
					role.m_vocation = dis.readByte();
					Tools.debugPrintln("grade = " + role.m_grade);
					Tools.debugPrintln("vocation = " + role.m_vocation);
					if (listType == UISocial.SOCIAL_TYPE_BLACKLIST) {
						role.m_faction = dis.readByte();
						Tools.debugPrintln("m_faction = " + role.m_faction);
					}
				}
				if (listType == UISocial.SOCIAL_TYPE_FRIEND) {
					role.m_isWatering = dis.readByte(); // 是否能浇水
				}
				m_social_list[i] = role;
			}
			switch (listType) {
				case UISocial.SOCIAL_TYPE_FRIEND:
					m_yqs_xyjsFriend = m_social_list;
					m_friend_currentPage = currentPage;
					if (sumPag > 0) {
						m_friend_totalPage = sumPag;//总页数
						Tools.debugPrintln("m_friend_totalPage = " + m_friend_totalPage);
						refreshLost();
					}
					break;
				case UISocial.SOCIAL_TYPE_BLACKLIST:
					break;
			}

		}
		else {
//			Tools.debugPrintln("读取社交界面异常 : " + msg);
		}
	}

	public void logic()
	{
		// 1s的倒计时
//		if(m_isShowWater){
			ChatCountDown();
//		}
			if(isShowShu){
				m_gm_frame.addControl(m_ab_shu);
			}else{
				m_gm_frame.removeControl(m_ab_shu);
			}

	}
	//判断控件是否存在
	public DWImageBox isNewImageBox(){
		if(DWControlsManager.getInstance().contains(m_gm_frame) == false){
			return null;
		}else
			return m_gm_ib[m_gm_close];
	}
	
	public DWButton isNewButton(){
		if(DWControlsManager.getInstance().contains(m_gm_frame) == false){
			return null;
		}else
			return m_gm_bn02;
	}
	
	
	private int m_friend_currentPage;
	private int m_friend_totalPage = 1;
	public static int num = 6;
	
	/**
	 * 1s
	 */
	private long m_start_time = 0;
	private long m_next_second = 0;
	
	private long m_num = 0;

	public void ChatCountDown()
	{
		if (m_start_time == 0) {
			m_start_time = System.currentTimeMillis();///开始倒计时时截取系统时间
			m_next_second = m_start_time + 1000;
		}
		long m_currrent_time = System.currentTimeMillis();
		if (m_currrent_time >= m_next_second) {
			m_num++;
			if(m_num >= 2){
				unShow();
			}
			
			m_start_time = m_next_second;
			m_next_second += 1000;
		}
	}
}
